﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace RaidAnything.FS
{
    /// <summary>
    /// A block of data which has been encoded for storage
    /// </summary>
    public class EncodedBlock
    {
        /// <summary>
        /// Constructs the encoded representation of a block
        /// </summary>
        public EncodedBlock()
        {
            _numberOfDataBytes = 1;
            _numberOfRSBytes = 1;
        }

        [ContractVerification(false)]
        private static void ArrayCopy(Array source, Array dest, int length)
        {
            Array.Copy(source, dest, length);
        }

        [ContractInvariantMethod]
        private void ObjectInvariant()
        {
            Contract.Invariant(_numberOfRSBytes >= 1);
            Contract.Invariant(_numberOfDataBytes >= 1);
        }

        /// <summary>
        /// The unique id of the block
        /// </summary>
        public BlockId Id { get; set; }

        private int _numberOfDataBytes;
        private int _numberOfRSBytes;

        /// <summary>
        /// The ratio of data bytes to redundant bytes in the encoded block
        /// </summary>
        public double RecoveryRatio
        {
            get
            {
                return _numberOfDataBytes / _numberOfRSBytes;
            }
        }
    }
}
